package com.app.piemoment;

import android.content.Intent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.app.piemoment.config.Config;
import com.app.piemoment.database.SettingLoader;

public class ModuleActivity extends BaseActivity {
	
	private CheckBox btn_life;
	private CheckBox btn_value;
	private CheckBox btn_love;
	private CheckBox btn_communication;

	public ModuleActivity(){
		mainViewId = R.layout.module_activity;
	}

	@Override
	protected void initMainView() {
		initTitle(R.drawable.btn_back_bg, "测试模块选择", 0, 0);
		
		btn_life = (CheckBox)findViewById(R.id.button1);
		btn_value = (CheckBox)findViewById(R.id.button2);
		btn_love = (CheckBox)findViewById(R.id.button3);
		btn_communication = (CheckBox)findViewById(R.id.button4);
		
		btn_life.setChecked(SettingLoader.getLifeCheck(this));
		btn_value.setChecked(SettingLoader.getValueCheck(this));
		btn_love.setChecked(SettingLoader.getLoveCheck(this));
		btn_communication.setChecked(SettingLoader.getTogetherCheck(this));

	}

	@Override
	protected void registerMainViewEvent() {
		OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				Intent intent = new Intent(ModuleActivity.this,TesttingActivity.class);
				switch (buttonView.getId()) {
				case R.id.button1:
					SettingLoader.setLifeCheck(ModuleActivity.this,isChecked);
					intent.putExtra("module", Config.Modoule_Lift);
					break;
				case R.id.button2:
					SettingLoader.setValueCheck(ModuleActivity.this,isChecked);
					intent.putExtra("module", Config.Modoule_Personality);
					break;
				case R.id.button3:
					SettingLoader.setLoveCheck(ModuleActivity.this,isChecked);
					intent.putExtra("module", Config.Modoule_Love);
					break;
				case R.id.button4:
					SettingLoader.setTogetherCheck(ModuleActivity.this,isChecked);
					intent.putExtra("module", Config.Modoule_Communication);
					break;

				default:
					break;
				}
				startActivity(intent);
			}
		};
		
		btn_life.setOnCheckedChangeListener(checkListener);
		btn_value.setOnCheckedChangeListener(checkListener);
		btn_love.setOnCheckedChangeListener(checkListener);
		btn_communication.setOnCheckedChangeListener(checkListener);
		
	}

	@Override
	protected void processMainView() {

	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_left:
			super.onBackPressed();
			break;

		default:
			break;
		}
	}

}
